'use strict';

navigator.getUserMedia = navigator.getUserMedia ||
    navigator.webkitGetUserMedia || navigator.mozGetUserMedia;

let constraints = { // 音频、视频约束
    audio: true, // 指定请求音频Track
    video: {  // 指定请求视频Track
        mandatory: { // 对视频Track的强制约束条件
            width: {min: 320},
            height: {min: 180}
        },
        optional: [ // 对视频Track的可选约束条件
            {frameRate: 30}
        ]
    }
};

let constraint = {video: true};

let video = document.querySelector('video');

function successCallback(stream) {
    if (window.URL) {
        video.src = window.URL.createObjectURL(stream);
        video.play();
    } else {
        video.src = stream;
    }
}

function errorCallback(error) {
    console.log('navigator.getUserMedia error: ', error);
}

navigator.getUserMedia(constraint, successCallback, errorCallback);